﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Hengyuantong.SmartRail.Configuration;
using Hengyuantong.SmartRail.Web;

namespace Hengyuantong.SmartRail.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class SmartRailDbContextFactory : IDesignTimeDbContextFactory<SmartRailDbContext>
    {
        public SmartRailDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<SmartRailDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            SmartRailDbContextConfigurer.Configure(builder, configuration.GetConnectionString(SmartRailConsts.ConnectionStringName));

            return new SmartRailDbContext(builder.Options);
        }
    }
}
